package com.atguigu.gmall.order.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.cart.CartFeignClient;
import com.atguigu.gmall.model.order.vo.OrderSubmitVo;
import com.atguigu.gmall.order.biz.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:lyd
 **/
@RestController
@RequestMapping("api/order/auth")
public class OrderRestController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private CartFeignClient cartFeignClient;

    /**
     * 提交订单
     * @param tradeNo
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestParam("tradeNo") String tradeNo,
                              @RequestBody OrderSubmitVo submitVo){
        //1、生成订单
        Long orderId=orderService.submitOrder(tradeNo,submitVo);
        //2、删除购物车中选中的商品
        cartFeignClient.deleteChecked();
        return Result.ok(orderId.toString());
    }
}
